package com.fingard.dsp.bank.reqrespobj.single;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RequestBase;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
import com.fingard.dsp.bank.reqrespobj.single.detail.ReqPayRecDetail;
import com.fingard.xml.XmlTextReader;

import java.util.Map;

public class ReqSingle extends RequestBase{

	public ReqPayRecDetail singleDetail = null;
	
	private XmlTextReader xmlReader;
	
	public ReqSingle(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception{
		init(p_xmlReader, p_header);
	}

    public ReqSingle(Map<String,String> map, ReqRespHeader p_header) throws Exception {
        init(map, p_header);
    }

	private void init(XmlTextReader p_xmlReader, ReqRespHeader p_header) throws Exception{
		reqHeader = p_header;
		xmlReader = p_xmlReader;
		
		if(xmlReader.read(PATH_Detail)){//"/ATSYH/TransReq/TransParam/DetailRecord"
			singleDetail = new ReqPayRecDetail(xmlReader.readedXElement, reqHeader.transType,p_header.bankCode);
		}
		else{
			throw new Exception("不存在节点："+PATH_Detail);
		}
	}

    private void init(Map<String,String> map, ReqRespHeader p_header) throws Exception{
        reqHeader = p_header;
        singleDetail = new ReqPayRecDetail(map);
    }
	
	public ReqSingle(ReqRespHeader p_header) throws Exception{
		reqHeader = p_header;
	}
	
	public ReqSingle(ReqBatPayRec p_reqBat) throws Exception{
		reqHeader = p_reqBat.reqHeader.clone();
		xmlReader = new XmlTextReader(p_reqBat.getOriReqXml());
		init(xmlReader, reqHeader);
	}
	
	public String getOriReqXml(){
		return xmlReader.getOriXmlString();
	}
}
